<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%
    String path = request.getContextPath();
	String basePath = "/";
%>
<!DOCTYPE html>
<html lang="en">
<head>
    <base href="/">
    <!-- 下拉框 -->
    <link rel="stylesheet" href="static/ace/css/chosen.css"/>
    <!-- jsp文件头和头部 -->
    <%@ include file="../index/top.jsp" %>
</head>
<body class="no-skin">
<!-- /section:basics/navbar.layout -->
<div class="main-container" id="main-container">
    <!-- /section:basics/sidebar -->
    <div class="main-content">
        <div class="main-content-inner">
            <div class="page-content">
                <div class="row">
                    <div class="col-xs-12">
                        <form action="plantbase/${msg }.do" name="plantbaseForm" id="plantbaseForm" method="post">
                            <c:if test="${plantbase.id !=null}">
                                <input type="hidden" name="id" id="id" value="${plantbase.id }"/>
                            </c:if>
                            <input type="hidden" id="state" value="${state}"/>
                            <div id="zhongxin" style="padding-top: 13px;">
                                <table id="table_report" class="table table-striped table-bordered table-hover">
                                    <tr>
                                        <td style="width:79px;text-align: right;padding-top: 13px;">基地编码:</td>
                                        <td><input type="text" name="code" id="code" value="${plantbase.code }"
                                                   maxlength="32" placeholder="这里输入基地编号" title="基地编号" onchange="hasN()"
                                                   style="width:98%;"/></td>
                                    </tr>
                                    <tr>
                                        <td style="width:79px;text-align: right;padding-top: 13px;">基地名称:</td>
                                        <td><input type="text" name="name" id="name" value="${plantbase.name }"
                                                   maxlength="32" placeholder="这里输入基地名称" title="基地名称" onchange="hasU()"
                                                   style="width:98%;"/></td>
                                    </tr>
                                    <tr>
                                        <td style="width:79px;text-align: right;padding-top: 13px;">所在城市:</td>
                                        <td><input type="text" name="city" id="city" value="${plantbase.city }"
                                                   maxlength="32" placeholder="这里输入基地所在城市" title="基地城市"
                                                   onchange="hasU()" style="width:98%;"/></td>
                                    </tr>
                                    <tr>
                                        <td style="width:79px;text-align: right;padding-top: 13px;">地址:</td>
                                        <td><input type="text" name="address" id="address" value="${plantbase.address }"
                                                   maxlength="64" placeholder="这里输入地址" title="地址" style="width:98%;"/>
                                        </td>
                                    </tr>

                                    <c:if test="${state !='01'}">
                                        <tr>
                                            <td style="width:79px;text-align: right;padding-top: 13px;">气温(℃):</td>
                                            <td><input type="text" name="temperature" id="temperature"
                                                       value="${plantbase.temperature }" maxlength="32"
                                                       placeholder="这里输入气温" title="气温" style="width:98%;"/></td>
                                        </tr>
                                        <tr>
                                            <td style="width:79px;text-align: right;padding-top: 13px;">天气:</td>
                                            <td><input type="text" name="weather" id="weather"
                                                       value="${plantbase.weather }" maxlength="32" placeholder="这里输入天气"
                                                       title="天气" style="width:98%;"/></td>
                                        </tr>
                                    </c:if>
                                    <tr>
                                        <td style="width:79px;text-align: right;padding-top: 13px;">环境描述:</td>
                                        <td><textarea name="content" id="content" rows="5" cols="30"
                                                      placeholder="这里输入环境信息" title="环境描述"
                                                      style="width:98%;">${plantbase.content }</textarea></td>
                                    </tr>
                                </table>
                                <table id="table_report1" class="table table-striped table-bordered table-hover">
                                    <tr>
                                        <td style="text-align: center;" colspan="10">
                                            <c:if test="${state =='01'}">
                                                <a class="btn btn-mini btn-primary" onclick="save();">保存</a>
                                            </c:if>
                                            <a class="btn btn-mini btn-danger" onclick="top.Dialog.close();">取消</a>
                                        </td>
                                    </tr>
                                </table>
                            </div>
                            <div id="zhongxin2" class="center" style="display:none"><br/><br/><br/><br/><img
                                    src="static/images/jiazai.gif"/><br/><h4 class="lighter block green"></h4></div>
                        </form>
                    </div>
                    <!-- /.col -->
                </div>
                <!-- /.row -->
            </div>
            <!-- /.page-content -->
        </div>
    </div>
    <!-- /.main-content -->
</div>
<!-- /.main-container -->
<!-- basic scripts -->
<!-- 页面底部js¨ -->
<%@ include file="../index/foot.jsp" %>
<!-- ace scripts -->
<script src="static/ace/js/ace/ace.js"></script>
<!-- inline scripts related to this page -->
<!-- 下拉框 -->
<script src="static/ace/js/chosen.jquery.js"></script>
<!--提示框-->
<script type="text/javascript" src="static/js/jquery.tips.js"></script>
</body>
<script type="text/javascript">
    $(top.hangge());
    $(function () {
        var state = $("#state").val();
        if (state != 01) {
            $("#table_report").find("input,button,textarea,select").attr("disabled", "disabled");
            /* $("#table_report1 tr:gt(0)").remove(); */
            /* $("#table_report1").hide(); */
        }

    });


    //保存
    function save() {
        if ($("#city").val() == "") {
            $("#city").tips({
                side: 3,
                msg: '请输入基地城市',
                bg: '#AE81FF',
                time: 2
            });
            $("#city").focus();
            return false;
        }
        if ($("#code").val() == "") {
            $("#code").tips({
                side: 3,
                msg: '请输入基地编号',
                bg: '#AE81FF',
                time: 2
            });
            $("#code").focus();
            return false;
        } else {
            $("#code").val($.trim($("#code").val()));
        }
        if ($.trim($("#name").val()) == "") {
            $("#name").tips({
                side: 3,
                msg: '输入基地名称',
                bg: '#AE81FF',
                time: 2
            });
            $("#name").focus();
            return false;
        } else {
            $("#name").val($.trim($("#name").val()));
        }

        if ($.trim($("#address").val()) == "") {
            $("#address").tips({
                side: 3,
                msg: '请输入基地地址',
                bg: '#AE81FF',
                time: 3
            });
            $("#address").focus();
            return false;
        } else {
            $("#address").val($.trim($("#address").val()));
        }
        var code = $.trim($("#code").val());
        var id = $.trim($("#id").val());
        var regCode = /^[a-zA-Z0-9]+$/;
        if (code == "") {
            $("#code").tips({
                side: 3,
                msg: '请输入基地编号',
                bg: '#AE81FF',
                time: 2
            });
            $("#code").focus();
            return false;
        } else {
            if (!regCode.test($("#code").val())) {
                $("#code").tips({
                    side: 3,
                    msg: '基地编号只能是字母或数字组成，请输入',
                    bg: '#AE81FF',
                    time: 2
                });
                $("#code").focus();
                return false;
            } else {
                $.ajax({
                    type: "POST",
                    url: '<%=basePath%>plantbase/hasN.do',
                    data: {id: id, code: code, tm: new Date().getTime()},
                    dataType: 'json',
                    cache: false,
                    success: function (data) {
                        if ("success" != data.result) {
                            $("#code").tips({
                                side: 3,
                                msg: '编号 ' + code + ' 已存在',
                                bg: '#AE81FF',
                                time: 3
                            });
                        } else {
                            var name = $.trim($("#name").val());
                            if (name == "") {
                                $("#name").tips({
                                    side: 3,
                                    msg: '输入基地名称',
                                    bg: '#AE81FF',
                                    time: 2
                                });
                                $("#name").focus();
                                return false;
                            } else {
                                $.ajax({
                                    type: "POST",
                                    url: '<%=basePath%>plantbase/hasU.do',
                                    data: {id: id, name: name, tm: new Date().getTime()},
                                    dataType: 'json',
                                    cache: false,
                                    success: function (data) {
                                        if ("success" != data.result) {
                                            $("#name").tips({
                                                side: 3,
                                                msg: '基地名称 ' + name + ' 已存在',
                                                bg: '#AE81FF',
                                                time: 3
                                            });
                                        } else {
                                            $("#plantbaseForm").submit();
                                            $("#zhongxin").hide();
                                            $("#zhongxin2").show();
                                        }
                                    }
                                });
                            }
                        }
                    }
                });
            }
        }

    }

    //判断基地名称是否存在
    function hasU() {
        var name = $.trim($("#name").val());
        var id = $.trim($("#id").val());
        if (name == "") {
            $("#name").tips({
                side: 3,
                msg: '输入基地名称',
                bg: '#AE81FF',
                time: 2
            });
            $("#name").focus();
            return false;
        } else {
            $.ajax({
                type: "POST",
                url: '<%=basePath%>plantbase/hasU.do',
                data: {id: id, name: name, tm: new Date().getTime()},
                dataType: 'json',
                cache: false,
                success: function (data) {
                    if ("success" != data.result) {
                        $("#name").tips({
                            side: 3,
                            msg: '基地名称 ' + name + ' 已存在',
                            bg: '#AE81FF',
                            time: 3
                        });
                    }
                }
            });
        }
    }

    //判断编号是否存在
    function hasN() {
        var code = $.trim($("#code").val());
        var id = $.trim($("#id").val());
        var regCode = /^[a-zA-Z0-9]+$/;
        if (code == "") {
            $("#code").tips({
                side: 3,
                msg: '请输入基地编号',
                bg: '#AE81FF',
                time: 2
            });
            $("#code").focus();
            return false;
        } else {
            if (!regCode.test($("#code").val())) {
                $("#code").tips({
                    side: 3,
                    msg: '基地编号只能是字母或数字组成，请输入',
                    bg: '#AE81FF',
                    time: 2
                });
                $("#code").focus();
                return false;
            } else {
                $.ajax({
                    type: "POST",
                    url: '<%=basePath%>plantbase/hasN.do',
                    data: {id: id, code: code, tm: new Date().getTime()},
                    dataType: 'json',
                    cache: false,
                    success: function (data) {
                        if ("success" != data.result) {
                            $("#code").tips({
                                side: 3,
                                msg: '编号 ' + code + ' 已存在',
                                bg: '#AE81FF',
                                time: 3
                            });
                        }
                    }
                });
            }
        }

    }
</script>
</html>